/*
 * @Description: 
 * @Author: HYH
 * @email: HYH_0716@163.com
 * @version: 
 * @Date: 2025-10-19 13:07:47
 * @LastEditors: your name
 * @LastEditTime: 2025-11-06 16:38:06
 */
import React,{ useId } from 'react';
import type { FormProps } from 'antd';
import { Button, Checkbox, Form, Input } from 'antd';
import { useNavigate, useLocation } from 'react-router-dom';
import { useAuth } from '../../hooks/useAuth';
import './login.css'
type FieldType = {
    username?: string;
    password?: string;
    remember?: string;
};

const Login =()=>{
    const token = useId();
    const  navigate = useNavigate();
    const location = useLocation();
    const { login } = useAuth();

    const redirectPath = location.state?.from || '/largeSize';
    const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
         // 实际项目替换为接口返回的token
        console.log(token,'useId');
        login(token); // 存储token，更新登录状态
        navigate(redirectPath, { replace: true }); // 跳转到目标页面
        console.log('Success:', values);
    };
    const onFinishFailed: FormProps<FieldType>['onFinishFailed'] = (errorInfo) => {
        console.log('Failed:', errorInfo);
    };
    return (
        <div className="login">
            <Form
                className='HYH'
                name="basic"
                labelCol={{ span: 8 }}
                wrapperCol={{ span: 16 }}
                initialValues={{ remember: true }}
                onFinish={onFinish}
                onFinishFailed={onFinishFailed}
                autoComplete="off"
            >
                <Form.Item<FieldType>
                    label="名称"
                    name="username"
                    rules={[{ required: true, message: '请输入名称!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item<FieldType>
                    label="密码"
                    name="password"
                    rules={[{ required: true, message: '请输入密码!' }]}
                >
                    <Input.Password />
                </Form.Item>

                <Form.Item<FieldType> name="remember" valuePropName="checked" label={null}>
                    <Checkbox>Remember me</Checkbox>
                </Form.Item>

                <Form.Item label={null}>
                    <Button type="primary" htmlType="submit">
                        Submit
                    </Button>
                </Form.Item>
            </Form>
        </div>
    )
}
export default Login
